home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / SunSoft.CafeDelSol / ScrollMap / spam < prev   
Text File  |  1996-02-01  |  15KB  |  494 lines

  1. import java.awt.*;
  2. import java.awt.image.*;
  3. import java.net.*;
  4. import java.net.MalformedURLException;
  5. import java.util.StringTokenizer;
  6.  
  7. class ImageLoader extends Thread {
  8.         ScrollMap parent;
  9.         Image img;
  10.         
  11.         ImageLoader (ScrollMap parent) {
  12.                 this.parent = parent;
  13.                 start();
  14.                 }
  15.         public void run() {
  16.         int n = 0;
  17.                 while (n < (parent.nimgs -1)) {
  18.         n++;
  19.         img = parent.getImage (parent.getDocumentBase(), parent.img_dir + "/" + parent.urlarr[n]);
  20.  
  21.  
  22.  
  23.                   if (parent.numimgarr[n] != 0) {
  24.             parent.animgarr[n] = new MyImage( parent, n, parent.numimgarr[n], parent.urlarr[n]);
  25.           }
  26.  
  27.  
  28.  
  29.         parent.ldimage =  false;
  30.                 parent.add(img, n);
  31.            }
  32.         }
  33. }
  34.  
  35. class MyImage extends Thread {
  36.  
  37.     Image animg[] ;
  38.     ScrollMap parent;
  39.     String url;
  40.  
  41.     int N;
  42.     int which = 1;
  43.     int skip = 0;
  44.  
  45. public void run() {
  46.      for ( int nn=1;nn < (parent.numimgarr[N] +1 );nn++) {
  47.          animg[nn] = parent.getImage (parent.getDocumentBase(), parent.img_dir + "/" + parent.urlarr[N] + nn);
  48.          if (animg[nn] == null) { break;}
  49.      }
  50. }
  51.  
  52. MyImage ( ScrollMap parent, int n, int nimgs, String url) {
  53.  
  54. this.parent = parent;
  55. N = n;
  56. this.url = url;
  57. animg = new Image[nimgs+1];
  58.  
  59. start();
  60. }
  61.  
  62. public class ScrollMap extends java.applet.Applet implements Runnable {
  63.  
  64.     Image offscrImg;
  65.     Graphics offscrG; 
  66.  
  67.     boolean onarr[];
  68.  
  69.     Image imgs[];
  70.     MyImage animgarr[];
  71.  
  72.     String param; 
  73.     String prev; 
  74.     String current; 
  75.  
  76.     String urlarr[] = new String [64];
  77.     String destarr[] = new String [64];
  78.     String namearr[] = new String [64];
  79.     String soundarr[] = new String [64];
  80.  
  81.     int numimgarr[] = new int [64];
  82.     int skiparr[] = new int [64];
  83.     int backarr[] = new int [64];
  84.     int widtharr[] = new int [64];
  85.     int accum[] = new int [64];
  86.     int num = 1;
  87.     int n;
  88.     int pos;
  89.     int fix;
  90.     int newpos;
  91.     int nimgs;
  92.     int width;
  93.     int height;
  94.     int totalwidth = 0;  
  95.     int x, newx;
  96.     int dist = 1;
  97.     int timeout = 200;
  98.     int mousepos;
  99.  
  100.     Thread scroller;
  101.  
  102.     String img_dir;
  103.     String showstat;
  104.     String before;
  105.     String after;
  106.     String url;
  107.     String dir;
  108.     String statuschk;
  109.  
  110.     boolean ldimage = false;
  111.     boolean loaded;
  112.     boolean top;
  113.     boolean in = false;
  114.  
  115.     URL anchor;
  116.  
  117.  
  118.     public void debug (String s) {
  119.     System.out.println(s);
  120.     }
  121.    
  122.     public void init () {
  123.  
  124.     String at = getParameter("before");
  125.     before = (at != null) ? at : "";
  126.     at = getParameter("after");
  127.     after = (at != null) ? at : "";
  128.     at = getParameter("img_dir");
  129.     img_dir = (at != null) ? at : "doc:/demo/images/duke";
  130.     at = getParameter("speed");
  131.     timeout = 1000 / ((at == null) ? 4 : Integer.valueOf(at).intValue());
  132.     at = getParameter("dir");
  133.     dist = (at == null) ? 5 : Integer.valueOf(at).intValue();
  134.         width = size().width;
  135.         height = size().height;
  136.     newx = x = size().width;
  137.  
  138.         while (true) {   
  139.                 nimgs++;
  140.  
  141.         urlarr[nimgs] =  getParameter("url"+nimgs);
  142.         if (urlarr[nimgs] == null) { break;}
  143.         destarr[nimgs] = getParameter("dest"+nimgs);
  144.         namearr[nimgs] = getParameter("name"+nimgs);
  145.         soundarr[nimgs] = getParameter("sound"+nimgs);
  146.                 if (getParameter("background"+nimgs) != null) {
  147.                 backarr[nimgs] = Integer.valueOf(getParameter("background"+nimgs)).intValue();
  148.                 } else {
  149.                 backarr[nimgs] = 0;
  150.                 }
  151.             if (getParameter("skip"+nimgs) != null) {
  152.         skiparr[nimgs] = Integer.valueOf(getParameter("skip"+nimgs)).intValue(); 
  153.         } else {
  154.         skiparr[nimgs] = 0;
  155.         }
  156.             if (getParameter("numimg"+nimgs) != null) {
  157.         numimgarr[nimgs] = Integer.valueOf(getParameter("numimg"+nimgs)).intValue();
  158.         } else {
  159.         numimgarr[nimgs] = 0;
  160.         }
  161.                 if (urlarr[nimgs] == null) {
  162.                 break;
  163.                 }
  164.         }        
  165.     onarr = new boolean[nimgs+1];
  166.     imgs = new Image[nimgs+1];
  167.         animgarr = new MyImage[nimgs];
  168.  
  169.                 //offscrImg = createImage(width, height);
  170.                 //offscrG = offscrImg.getGraphics();
  171.  
  172.     }
  173.     public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h) {
  174.         if ((flags & WIDTH) != 0 ) {
  175.       n++;
  176.       if (n >= (nimgs-1) ){
  177.         for (n=1;n < nimgs; n++) {
  178.             int tmpW = imgs[n].getWidth(this);
  179.             totalwidth +=  tmpW;
  180.             widtharr[n] = tmpW;
  181.         }
  182.       }
  183.         }
  184.         return super.imageUpdate(img, flags, x, y, w, h);
  185.     }
  186.     public void showDocument(URL u) {
  187.         getAppletContext().showDocument(u);
  188.     }
  189.  
  190.     public synchronized void add(Image img, int n) {
  191.         imgs[n] = img;
  192.         
  193.         if (isActive()) {
  194.             repaint();
  195.         }
  196.         }
  197.  
  198.     public void start() {
  199.         if (!loaded) {
  200.             loaded = true;
  201.             new ImageLoader(this);
  202.         }
  203.     if (scroller == null) {
  204.         scroller = new Thread(this);
  205.         scroller.start();
  206.     }
  207.     }
  208.     public void stop() {
  209.     if (scroller != null) {
  210.         scroller.stop();
  211.         scroller = null;
  212.     }
  213.     }
  214.  
  215.     public void run() {
  216.     while (true) {
  217.     try {Thread.currentThread().sleep(timeout);} catch (InterruptedException e){}
  218.         scroll(dist);
  219.     }
  220.     }
  221.  
  222.     synchronized void scroll(int dist) {
  223.     repaint();
  224.     }
  225.  
  226.     public void update(Graphics g) {
  227.         newx += dist;
  228.     g.setColor(Color.lightGray);
  229.  
  230.     if (newx != x) {
  231.         int dist = newx - x;
  232.         if (dist > 0) {
  233.         for (x = newx ; x > width ; x -= Math.max(width - 2, totalwidth));
  234.         paint(g, 1, dist + 1);
  235.         } else {
  236.         for (x = newx ; x < 0 ; x += Math.max(width - 2, totalwidth));
  237.         paint(g, (width-1) + dist, width-1);
  238.         }
  239.         if ( in ) {
  240.         statusShow();
  241.         }
  242.     } else {
  243.         //paint(g);
  244.     }
  245.     }
  246.     public void paint(Graphics g, int fromx, int tox) {
  247.     paintbuffer(offscrG, fromx, tox);
  248.     g.drawImage(offscrImg, 0, 0, this);
  249.     }
  250.         
  251.  
  252.     public void paintbuffer(Graphics g, int fromx, int tox) {
  253.     int x = this.x;
  254.     newx = x;
  255.         fix = x;
  256.     int h = 0;
  257.     int w = 0;
  258.         int accum =0;
  259.         int tmpwidth =0;
  260.  
  261.     g.setColor(Color.lightGray);
  262.     g.fillRect(1, 1, width, height-2);
  263.     g.clipRect(1, 1, width, height-2);
  264.  
  265.  
  266.     for (int i = 0 ; i < nimgs ; i++) {
  267.         if (imgs[i] == null) {
  268.         continue;
  269.         }
  270.         w = imgs[i].getWidth(this);
  271.         h = imgs[i].getHeight(this);
  272.  
  273.  
  274.               if ( numimgarr[i] != 0 ) {
  275.                 if (backarr[i] != 0) {
  276.                 g.drawImage(imgs[i], x, height - (h+1), this);
  277.                 }
  278.                 if (animgarr[i].skip == skiparr[i] ) {
  279.                 animgarr[i].skip = 0;
  280.                 g.drawImage(animgarr[i].animg[animgarr[i].which], (x - tmpwidth), height - (h+1), this);     
  281.                 animgarr[i].which++;
  282.                 } else {    
  283.                 g.drawImage(animgarr[i].animg[animgarr[i].which], (x - tmpwidth), height - (h+1), this);     
  284.                 animgarr[i].skip++;
  285.                 }
  286.                 if (animgarr[i].which > numimgarr[i]) {
  287.                 animgarr[i].which = 1;
  288.                 }
  289.  
  290.               } else {
  291.                 g.drawImage(imgs[i], x, height - (h+1), this);
  292.               }  
  293.  
  294.             if ((x + w) > width) {
  295.                 x -= Math.max(width - 2, totalwidth);
  296.             }
  297.                 x += w;
  298.         }
  299. /*
  300. System.out.println( x + " ");
  301.                   for (int t = 1;t<nimgs+1;t++) {
  302.           tmpwidth = widtharr[t];
  303.           accum += tmpwidth; 
  304.  
  305.                    if (numimgarr[t] != 0) {
  306.                      g.drawImage(animgarr[t].animg[animgarr[t].which], (x - tmpwidth), height - (h+1), this);          
  307.                     animgarr[t].which++;
  308.                     if (animgarr[t].which > numimgarr[t]) {
  309.                         animgarr[t].which = 1;
  310.                     }
  311.                     }
  312.                    }
  313.  
  314. */
  315.         
  316.     }
  317.  
  318.  
  319.     public void paint(Graphics g) {
  320.  
  321.     //offscrG.draw3DRect(0, 0, width, height, true);
  322.     paint(g, 1, width-1);
  323.     }
  324.  
  325.    public void statusShow (){
  326.  
  327.        showStatus( showstat ) ;
  328.        accum[0] = 0;
  329.        pos = (-fix);
  330.        newpos = ((totalwidth - fix) - (totalwidth - width));
  331.        for (int i = 0 ;i < (nimgs - 1) ; i++) {
  332.  
  333.          if (pos < 0 ) {
  334.                 if ((width -mousepos) < newpos) {
  335.                     accum[0] = (accum[0] + widtharr[i]);
  336.                     if ( (newpos - (width - mousepos)) >= (accum[0]) && (newpos - (width - mousepos ) ) <= (accum[0]+widtharr[i+1])){
  337.             current = urlarr[i+1];
  338.             if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;} 
  339.             if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
  340.  
  341.             if (destarr[i+1] != null ) {
  342.             if (namearr[i+1] !=null ) {
  343.                                 showstat = "Click to select: " + namearr[i+1];
  344.             } else {
  345.                             if ( destarr[i+1].equals("same")) { 
  346.                                 showstat = "Click to select: " + urlarr[i+1];
  347.                             } else {   
  348.                                 showstat = "Click to select: " + destarr[i+1];
  349.                             } 
  350.             }
  351.                 } else {
  352.                showstat = " ";        
  353.                     }            
  354.                     break;
  355.                    }
  356.                 } else {
  357.                     accum[0] = (accum[0] + widtharr[i]);
  358.                     if ( ( (totalwidth - fix) + mousepos  >= accum[0] ) &&  ( (totalwidth - fix) + mousepos  <= (accum[0] + widtharr[i+1]) ) ) {
  359.             current = urlarr[i+1];
  360.             if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;} 
  361.             if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
  362.                     if (destarr[i+1] != null) { 
  363.                         if (namearr[i+1] != null ) { 
  364.                                 showstat = "Click to select: " + namearr[i+1];
  365.                         } else { 
  366.                     if ( destarr[i+1].equals("same")) {
  367.                                 showstat = "Click to select: " + urlarr[i+1];
  368.                 } else {
  369.                                 showstat = "Click to select: " + destarr[i+1];
  370.                             }                     
  371.                         } 
  372.                     } else {             
  373.                        showstat = " ";  
  374.                     } 
  375.                     break;
  376.                 }
  377.          }
  378.        } else {
  379.                    accum[0] = (accum[0] + widtharr[i]);
  380.                    if ( (pos + mousepos) >= (accum[0]) && (pos + mousepos ) <= (accum[0]+widtharr[i+1])){
  381.             current = urlarr[i+1];
  382.             if (!current.equals(prev)) { onarr[i+1] = false;} else { onarr[i+1] = true;} 
  383.             if (soundarr[i+1] != null && !onarr[i+1]) { play(getCodeBase(), soundarr[i+1]);}
  384.                     if (destarr[i+1] != null) { 
  385.                         if (namearr[i+1] != null ) { 
  386.                                 showstat = "Click to select: " + namearr[i+1];
  387.                         } else { 
  388.                             if ( destarr[i+1].equals("same") ) { 
  389.                                 showstat = "Click to select: " + urlarr[i+1];
  390.                             } else {   
  391.                                 showstat = "Click to select: " + destarr[i+1];
  392.                             } 
  393.                         } 
  394.                     } else {             
  395.                        showstat = " ";  
  396.                     } 
  397.                         break;
  398.                     }
  399.                 }
  400.         }
  401.  
  402.     prev = current;
  403.         return;
  404.     }
  405.  
  406.     public boolean handleEvent(Event evt) {
  407.     boolean mouse = true;
  408.     if (evt.id == Event.MOUSE_DOWN) {
  409.         
  410.        int mdx = evt.x;
  411.  
  412.        accum[0] = 0;
  413.        pos = (-fix);
  414.        newpos = ((totalwidth - fix) - (totalwidth - width));
  415.        for (int i = 0 ;i < (nimgs -1) ; i++) {
  416.  
  417.          if (pos < 0 ) {
  418.                 if ((width -mdx) < newpos) {
  419.                     accum[0] = (accum[0] + widtharr[i]);
  420.                     if ( (newpos - (width - mdx)) >= (accum[0]) && (newpos - (width - mdx ) ) <= (accum[0]+widtharr[i+1])){
  421.             if ( destarr[i+1] == null ) { continue; }
  422.             if ( destarr[i+1].equals("same") ) { 
  423.                        try {
  424.                        anchor = new URL(null,  before + urlarr[i+1] + after);
  425.                        } catch (MalformedURLException e) {
  426.                        anchor = null;
  427.                        }
  428.                     } else {
  429.                        try { 
  430.                        anchor = new URL(null,  destarr[i+1]);showStatus("Fetching ...");showDocument(anchor);
  431.                        } catch (MalformedURLException e) { 
  432.                        anchor = null; 
  433.                        }
  434.                     }
  435.                    break;
  436.                    }
  437.                 } else {
  438.                     accum[0] = (accum[0] + widtharr[i]);
  439.                     if ( ( (totalwidth - fix) + mdx  >= accum[0] ) &&  ( (totalwidth - fix) + mdx  <= (accum[0] + widtharr[i+1]) ) ) {
  440.                     if ( destarr[i+1] == null ) { continue; }
  441.                     if ( destarr[i+1].equals("same") ) { 
  442.                        try {  
  443.                        anchor = new URL(null,  before + urlarr[i+1] + after);showStatus("Fetching ...");showDocument(anchor); 
  444.                        } catch (MalformedURLException e) {  
  445.                        anchor = null; 
  446.                        } 
  447.                     } else {
  448.                        try {   
  449.                        anchor = new URL(null,  destarr[i+1]);showStatus("Fetching ...");showDocument(anchor); 
  450.                        } catch (MalformedURLException e) {   
  451.                        anchor = null;  
  452.                        } 
  453.                     }
  454.                     break;
  455.                 }
  456.          }
  457.        } else {
  458.                    accum[0] = (accum[0] + widtharr[i]);
  459.                    if ( (pos + mdx) >= (accum[0]) && (pos + mdx ) <= (accum[0]+widtharr[i+1])){
  460.                     if ( destarr[i+1] == null ) { continue; }
  461.                     if ( destarr[i+1].equals("same") ) { 
  462.                         try {    
  463.                         anchor = new URL(null,  before + urlarr[i+1] + after);showStatus("Fetching ...");showDocument(anchor); 
  464.                         } catch (MalformedURLException e) {    
  465.                         anchor = null;  
  466.                         } 
  467.                         } else {
  468.                         try {    
  469.                         anchor = new URL(null,  destarr[i+1]);showStatus("Fetching ...");showDocument(anchor); 
  470.                         } catch (MalformedURLException e) {     
  471.                         anchor = null;   
  472.                         }  
  473.                       }
  474.                         break;
  475.                     }
  476.                 }
  477.         }
  478.  
  479.  
  480.         }
  481.           if (evt.id == Event.MOUSE_MOVE) {
  482.             in = true;
  483.             mousepos = evt.x;
  484.           }
  485.           if (evt.id == Event.MOUSE_EXIT) {
  486.             showStatus( " ") ;
  487.         in = false;
  488.           }
  489.           return mouse;
  490.         }
  491.  
  492. }
  493.